package com.example.reagent_management.ui.history.adapter;

import android.annotation.SuppressLint;

import com.example.lib_base.adapter.BasePagingAdapter;
import com.example.reagent_management.R;
import com.example.reagent_management.room.entity.HistoryInfo;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListAdapter;

public class HistoryAdapter extends BasePagingAdapter<HistoryInfo> {


    public HistoryAdapter() {
        super(new DiffCallBack());
    }

    @Override
    protected int getItemLayout(int position) {
        return R.layout.item_history;
    }

    @Override
    protected void bindData(@NonNull ItemHelper helper, @Nullable HistoryInfo data) {
        helper.setText(R.id.name,data.getName());
        helper.setText(R.id.batch, data.getBatch());
        helper.setText(R.id.counts,data.getCounts().toString());
        if (data.getOperateType()){
            helper.setText(R.id.type,"入库");
        }else {
            helper.setText(R.id.type,"出库");
        }
    }

    @Override
    protected Integer[] getClickViewId() {
        return null;
    }

    private static class DiffCallBack extends DiffUtil.ItemCallback<HistoryInfo>{

        @Override
        public boolean areItemsTheSame(@NonNull HistoryInfo oldItem, @NonNull HistoryInfo newItem) {
            return oldItem.getHistory_id().equals(newItem.getHistory_id());
        }

        @SuppressLint("DiffUtilEquals")
        @Override
        public boolean areContentsTheSame(@NonNull HistoryInfo oldItem, @NonNull HistoryInfo newItem) {
            return oldItem == newItem;
        }
    }


}
